<template>
  <div class="form">
    <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
      <el-tab-pane label="User" name="first">User</el-tab-pane>
      <el-tab-pane label="Config" name="second">Config</el-tab-pane>
      <el-tab-pane label="Role" name="third">Role</el-tab-pane>
      <el-tab-pane label="Task" name="fourth">Task</el-tab-pane>
    </el-tabs>

    <icon-close class="close" @click="$router.push('/')" />
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      status-icon
      :rules="rules"
      label-width="120px"
      class="demo-ruleForm"
    >
      <el-form-item label="账号" prop="phone">
        <el-input v-model.number="ruleForm.phone" placeholder="手机号码" />
      </el-form-item>
      <el-form-item label="密码" prop="pass">
        <el-input
          v-model="ruleForm.pass"
          type="password"
          autocomplete="off"
          placeholder="密码"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="Login(ruleFormRef)">登录</el-button>
      </el-form-item>
      <div class="tips">
        <span @click="$router.push('/register')"
          >还没有加入我们？前往注册-></span
        >
      </div>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
import type { FormInstance } from "element-plus";

const ruleFormRef = ref<FormInstance>();
//表单数据
const ruleForm = reactive({
  phone: "",
  pass: "",
});

//校验账号
const checkPhone = (rule: any, value: any, callback: any) => {
  if (!value) {
    return callback(new Error("账号不能为空"));
  }
  setTimeout(() => {
    if (
      !/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(
        value
      )
    ) {
      callback(new Error("请输入正确的手机号码"));
    } else {
      callback();
    }
  }, 1000);
};

//登录
const Login = (formEl: FormInstance | undefined) => {};

//定义校验函数
const rules = reactive({
  phone: [{ validator: checkPhone, trigger: "blur" }],
});
</script>

<style lang="scss" scoped>
.demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}
.form {
  position: fixed;
  left: 25%;
  right: 35%;
  top: 10%;

  .close {
    float: right;
    padding: 0.05rem;
  }

  form {
    padding: 0.2rem;
    border-radius: 0.1rem;
    background-color: rgb(246, 246, 246);

    .tips {
      color: green;
      float: right;
      font-size: 0.05rem;
    }
  }
}

span {
  cursor: pointer;
}
</style>
